package com.xuan.friend.aop;


import com.xuan.common.core.constants.Constants;
import com.xuan.common.core.enums.ResultCode;
import com.xuan.common.core.exception.BusinessException;
import com.xuan.common.core.utils.ThreadLocalUtils;
import com.xuan.friend.domain.user.vo.UserDetailVo;
import com.xuan.friend.manager.UserCacheManager;
import jakarta.annotation.Resource;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class UserStatusCheckAspect {

    @Resource
    private UserCacheManager userCacheManager;

    @Before(value = "@annotation(com.xuan.friend.aop.CheckUserStatus)")
    public void before(JoinPoint joinPoint) {
        Long userId = ThreadLocalUtils.get(Constants.USER_ID, Long.class);
        UserDetailVo userDetailVo = userCacheManager.getUserById(userId);
        if (userDetailVo == null) {
            throw new BusinessException("未登录");
        }
        if (Constants.FALSE.equals(userDetailVo.getStatus())) {
            throw new BusinessException("您已被列入黑名单,请联系管理员");
        }
    }
}
